/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package controladores;

import entidades.miembros.Socio;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import utiles.json.JSONParser;
import utiles.json.Parser;

/**
 *
 * @author fcarou
 */
public class ControladorSocios extends BaseControlador
{    
    public ControladorSocios ()
    {
        super (Constantes.URL_COMPLETA + Constantes.SOCIOS);
    }
    
    public List<Socio> getSocios ()
    {
        String res = helper.doGet(Constantes.ALL, null, null);
        
        if (res == null)
            return null;
        
        JSONArray array = new JSONArray(res);
        
        if (array.length() == 0)
            return new ArrayList<>();
        
        List<Socio> socios = new Parser().parseArray(array, Socio.class);
        
        return socios;
    }
    
    public List<Socio> getSocios (String cadena)
    {        
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("cadena", cadena));
        
        String res = helper.doGet(Constantes.POR_CADENA, null, params);
        
        if (res == null)
            return null;
        
        System.out.println(res);
        
        JSONParser<Socio> parser = new JSONParser<>(Socio.class);
        
        return parser.parseArray(res);
    }
}
